Developer Documentation

QuickTime 4 API Documentation

Inside Macintosh: Macintosh Toolbox Essentials

Previous | Chapter Top | Chapter Contents | Next |

Moving Windows

This section describes the functions that move windows on the desktop.

To move a window, your application ordinarily needs to call only the DragWindow function (DragWindow) , which itself calls the DragGrayRgn function (DragGrayRgn) , and the MoveWindow function (MoveWindow) . The DragGrayRgn function drags a dotted outline of the window on the screen, following the motion of the cursor, as long as the user holds down the mouse button. The DragGrayRgn function itself calls the PinRect function (PinRect) to contain the point where the cursor was when the mouse button was first pressed inside the available desktop area. When the user releases the mouse button, DragWindow calls MoveWindow , which moves the window to a new location.

DragWindow

Moves a window on the screen when the user drags it by its title bar.

pascal void DragWindow (WindowPtr theWindow,
                     Point startPt,
                     const Rect *boundsRect);
theWindow
A pointer to the window record of the window to be dragged.
startPt
The location, in global coordinates, of the cursor at the time the user pressed the mouse button. Your application retrieves this point from the where field of the event record.
boundsRect
A pointer to a rectangle, given in global coordinates, that limits the region to which a window can be dragged. If the mouse button is released when the cursor is outside the limits of boundsRect , DragWindow returns without moving the window (or, if it was inactive, without making it the active window).
Because the user cannot ordinarily move the cursor off the desktop, you can safely set boundsRect to the largest available rectangle (the bounding box of the desktop region pointed to by the global variable GrayRgn ) when you're using DragWindow to track mouse movements. Don't set the bounding rectangle to the size of the immediate screen ( screenBits.bounds ), because the user wouldn't be able to move the window to a different screen on a system equipped with multiple monitors .

DESCRIPTION

The DragWindow function uses DragGrayRgn (DragGrayRgn) to move a dotted outline of the specified window around the screen, following the movement of the cursor until the user releases the mouse button. When the button is released, DragWindow calls MoveWindow (MoveWindow) to move the window to its new location. If the specified window isn't the active window (and the Command key wasn't down when the mouse button was pressed), DragWindow makes it the active window by setting the front parameter to true when calling MoveWindow . If the Command key was down when the mouse button was pressed, DragWindow moves the window without making it active.

MoveWindow

Moves a window on the desktop.

pascal void MoveWindow (WindowPtr theWindow,
                     short hGlobal,
                     short vGlobal,
                     Boolean front);
theWindow
A pointer to the window record of the window being moved.
hGlobal
The new location, in global coordinates, of the left edge of the window's port rectangle.
vGlobal
The new location, in global coordinates, of the top edge of the window's port rectangle.
front
A Boolean value specifying whether the window is to become the frontmost, active window. If the value of the front parameter is false , MoveWindow does not change its plane or status. If the value of the front parameter is true and the window isn't active, MoveWindow makes it active by calling the SelectWindow function.

DESCRIPTION

The MoveWindow function moves the specified window to the location specified by the hGlobal and vGlobal parameters, without changing the window's size. The upper-left corner of the window's port rectangle is placed at the point ( vGlobal , hGlobal ). The local coordinates of the upper-left corner are unaffected.

Your application doesn't normally call MoveWindow . When the user drags a window by dragging its title bar, you can call DragWindow (DragWindow) which in turn calls MoveWindow when the user releases the mouse button.

DragGrayRgn

The DragWindow function (DragWindow) calls the DragGrayRgn function to move an outline of a window around the screen as the user drags a window.

pascal long DragGrayRgn (RgnHandle theRgn,
                     Point startPt,
                     const Rect *limitRect,
                     const Rect *slopRect,
                     short axis,
                     DragGrayRgnProcUPP actionProc);
theRgn
A handle to the region to be dragged.
startPt
The location, in the local coordinates of the current graphics port, of the cursor when the mouse button was pressed.
limitRect
A pointer to a rectangle, given in the local coordinates of the current graphics port, that limits where the region can be dragged. This parameter works with the slopRect parameter, as illustrated in Figure 3-1 .
slopRect
A pointer to a rectangle, given in the local coordinates of the current graphics port, that gives the user some leeway in moving the mouse without violating the limits of the limitRect parameter, as illustrated in Figure 3-1 . The slopRect rectangle should be larger than the limitRect rectangle.
axis
A constant that constrains the region's motion. The axis parameter can have one of these values (defined by the Control Manager):
                enum {
                    noConstraint    = 0,    /* no constraints */
                    hAxisOnly       = 1,    /* move on horizontal axis
                                            /* only */
                    vAxisOnly       = 2     /* move on vertical axis */
                                            /* only */
                };
If an axis constraint is in effect, the outline follows the cursor's movements along only the specified axis, ignoring motion along the other axis. With or without an axis constraint, the outline appears only when the mouse is inside the slopRect rectangle.
actionProc
A pointer to a function that defines an action to be performed repeatedly as long as the user holds down the mouse button. The function can have no parameters. If the value of actionProc is nil , DragGrayRgn simply retains control until the mouse button is released.

DESCRIPTION

The DragGrayRgn function moves a gray outline of a region on the screen, following the movements of the cursor, until the mouse button is released. It returns the difference between the point where the mouse button was pressed and the offset point --that is, the point in the region whose horizontal and vertical offsets from the upper-left corner of the region's enclosing rectangle are the same as the offsets of the starting point when the user pressed the mouse button. The DragGrayRgn function stores the vertical difference between the starting point and the offset point in the high-order word of the return value and the horizontal difference in the low-order word.

The DragGrayRgn function limits the movement of the region according to the constraints set by the limitRect and slopRect parameters:

Figure 3-1 illustrates how the region stops moving when the offset point reaches the edge of the limitRect rectangle. The cursor continues to move, but the region does not.

If the mouse button is released while the cursor is anywhere inside the slopRect rectangle, the Window Manager redraws the window in its new location, which is calculated from the value returned by DragGrayRgn .

Figure 1 Limiting rectangle used by DragGrayRgn

ASSEMBLY-LANGUAGE INFORMATION

You can set the global variable DragHook to point to an optional function, defined by your application, which will be called by DragGrayRgn as long as the mouse button is held down. (If there's an actionProc function, it is called first.) If you want DragGrayRgn to draw the region's outline in a pattern other than gray, you can store the pattern in the global variable DragPattern and then invoke the macro _DragTheRgn . Note that the use of the Window Manager's global variables is not guaranteed to be compatible with system software versions later than System 6.

PinRect

The DragGrayRgn function uses the PinRect function to contain a point within a specified rectangle.

pascal long PinRect (const Rect *theRect, Point *thePt);
theRect
A pointer to a rectangle in which the point is to be contained.
thePt
A pointer to the point to be contained.

DESCRIPTION

The PinRect function returns a point within the specified rectangle that is as close as possible to the specified point. (The high-order word of the returned long integer is the vertical coordinate; the low-order word is the horizontal coordinate.)

If the specified point is within the rectangle, PinRect returns the point itself. If not, then

The 1 is subtracted when the point is below or to the right of the rectangle so that a pixel drawn at that point lies within the rectangle. If the point is exactly on the bottom or the right edge of the rectangle, however, 1 should be subtracted but isn't.


© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next